package com.zmn.oms.api.controller.third.deshiman;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zmn.base.engineer.common.dro.foreign.engineer.ForeignEngineerDetailInfoDRO;
import com.zmn.base.engineer.dubbo.interfaces.foreign.EngineerListRemoteService;
import com.zmn.base.oms.common.model.es.orderwork.*;
import com.zmn.base.product.dubbo.interfaces.product.foreign.ProductBusinessLineForeignListRemoteService;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dictionary.GlobalDict;
import com.zmn.common.dto2.Option;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.math.MoneyUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.office.excel.ExportExcelBuilder;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.mcc.common.dto.staff.StaffDRO;
import com.zmn.mcc.dubbo.interfaces.staff.StaffListRemoteService;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.common.utils.MobileUtil;
import com.zmn.oms.model.entity.work.OrderWorkQuery;
import com.zmn.oms.third.deshiman.DeshimanConsts;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkQueryBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2020/11/30 10:49
 */
@Controller
@RequestMapping("/deshiman")
@Slf4j
public class DeshimanController {

    @Autowired
    private ZsOrderWorkQueryBService zsOrderWorkQueryBService;
//    @Reference(version = com.zmn.mer.dubbo.utils.DubboConsts.INTERFACE_VERSION, check = false)
//    protected FactoryListRemoteService factoryListRemoteService;
    @Reference(version = com.zmn.base.engineer.common.constants.DubboConsts.INTERFACE_VERSION, check = false)
    protected EngineerListRemoteService engineerListRemoteService;
    @Reference(version = com.zmn.mcc.dubbo.dto.DubboConsts.INTERFACE_VERSION, check = false)
    protected StaffListRemoteService staffListRemoteService;
    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    protected ProductBusinessLineForeignListRemoteService productBusinessLineForeignListRemoteService;

    private final static Pattern shopNamePattern = Pattern.compile(".*?\"shopName\":\"(.+?)\"[,|\\}].*?");

    private final static LinkedHashMap<String, String> sheetOneMap = Maps.newLinkedHashMap();
    static {
        LinkedHashMap<String, String> map = sheetOneMap;
        map.put("platCallback", "下单平台");
        map.put("receiveTime", "下单时间");
        map.put("firstDutyTime", "首次预约时间");
        map.put("firstDutyOptTime", "首次操作预约时间点");
        map.put("lastDutyTime", "末次预约时间");
        map.put("lastDutyOptTime", "末次操作预约时间点");
        map.put("suspendTime", "挂起时间");
        map.put("distributeTime", "派单时间");
        map.put("visitTime", "上门时间");
        map.put("cancelTimeCallback", "取消时间");
        map.put("serviceCompleteTime", "服务完成时间");
        map.put("completeTime", "完成时间");
        map.put("accountTime", "算账时间");

        map.put("id", "工单号");
        map.put("extOuterId", "渠道父订单号");
        map.put("extOuterSubId", "渠道子订单号");
        map.put("companyName", "子公司");
        map.put("provinceName", "省份");
        map.put("naturalCityName", "城市");
        map.put("countyName", "区域");
        map.put("addressCallback", "地址");

        map.put("userNameCallback", "用户姓名");
        map.put("userPhoneNameCallback", "用户电话");
        map.put("genderCallback", "性别");

        map.put("factoryCallback", "厂商");
        map.put("factoryProductCallback", "厂商产品");

        map.put("bizTypeCallback", "业务类型");
        map.put("bizLineCallback", "业务线");
        map.put("servProductGroupName", "产品组");
        map.put("servCategName", "服务分类");
        map.put("showProductCallback", "前台服务产品");
        map.put("productCallback", "后台服务产品");
        map.put("productUnitCallback", "产品单位");
        map.put("productBrandCallback", "产品品牌");
        map.put("productNumCallback", "数量");
        map.put("typeName", "返修新单");
        map.put("standardPriceCallback", "标准收费单");
        map.put("finalPriceRateCallback", "是否一口价");

        map.put("originalIdCallback", "源单号");
        map.put("faultContent", "故障内容");
        map.put("remark", "下单备注");
        map.put("platWorkCallback", "服务平台");
        map.put("serviceProviderCallback", "服务商");

        map.put("masterNameCallback", "主工程师");
        map.put("slaveMasterNameCallback", "多工程师");
        map.put("masterSupervisorNameCallback", "工程师主管");
        map.put("reworkMasterNameCallback", "源工程师");
        map.put("statusName", "状态");
        map.put("resultStatusName", "结果");
        map.put("originalAmountCallback", "订单金额");
        map.put("discountAmountCallback", "优惠");
        map.put("totalAmountCallback", "订单收入");
        map.put("channelPrepayAmountCallback", "渠道预收");
        map.put("depositAmountCallback", "定金");
        map.put("masterAmountCallback", "工程师收款金额");
        map.put("refundAmountCallback", "退款金额");
        map.put("channelAmountCallback", "渠道费");

        map.put("payStatusName", "支付状态");
        map.put("suspendContent", "挂起原因");
        map.put("cancelContentCallback", "取消原因");
        map.put("channelName", "下单渠道");
        map.put("outerId", "渠道单号");
        map.put("shopName", "店铺名称");
        map.put("receiverNameCallBack", "录单员");
        map.put("commentScore", "评星");
        map.put("replyContent", "回访评分内容");
        map.put("orderNonstandardTitleOneCallback", "信息名称1");
        map.put("orderNonstandardContentOneCallback", "信息内容1");
        map.put("orderNonstandardTitleTwoCallback", "信息名称2");
        map.put("orderNonstandardContentTwoCallback", "信息内容2");
        map.put("orderNonstandardTitleThreeCallback", "信息名称3");
        map.put("orderNonstandardContentThreeCallback", "信息内容3");
    }

    /**
     * 导出
     */
    @RequestMapping("/export")
    public String export(String sign, String startDay, String endDay, String showTel, HttpServletResponse response)
            throws Exception {
        if (!"0e39fd66fa4b4b239a1c240815103dbf".equals(sign)) {
            return "Who are you???";
        }

        // 查询订单数据
        List<EsOrderWork> esOrderWorkList = null;
        try {
            esOrderWorkList = this.listOrderWork(startDay, endDay);
        } catch (OmsBaseException e) {
            return e.getMessage();
        }

        // 导出
        ExportExcelBuilder excelBuilder = this.getExportExcelBuilder(esOrderWorkList, sheetOneMap, "showTel".equals(showTel));
        excelBuilder.exportExcel(response, "工单管理");

        return null;
    }


    private ExportExcelBuilder getExportExcelBuilder(List<EsOrderWork> orderWorkList, Map<String, String> headerMap, boolean showTel) {
        ExportExcelBuilder excel = new ExportExcelBuilder();

        ExportExcelBuilder.ExcelSheet<EsOrderWork> sheet1 = excel.createExcelSheet(
                "工单信息", orderWorkList, headerMap, true);

        Map<Integer, String> staffMap;
        Map<Integer, String> masterMap;
        Map<Integer, String> fcMap;
        {
            // 录单人处理
            List<Integer> receiverIdList = orderWorkList.stream()
                    //剔除系统和null
                    .map(EsOrderWork::getReceiverId)
                    .map(Long::intValue)
                    .filter(receiverId -> GlobalConsts.OPERATE_USER_TYPE_SYSTEM != receiverId)
                    .collect(Collectors.toList());

            // 查询员工信息-录单员
            if (receiverIdList.size() > 0) {
                // 员工
                ResponseDTO<List<StaffDRO>> staffListResp =  staffListRemoteService.listStaffByStaffIds(receiverIdList, null);
                staffMap = Optional.ofNullable(staffListResp.getData())
                        .filter(list -> list.size() > 0)
                        .map(list -> list.stream()
                                .collect(Collectors.toMap(StaffDRO::getStaffId, StaffDRO::getRealName, (k1, k2) -> k1))
                        )
                        .orElseGet(Collections::emptyMap);
                // 师傅
                // todo fubiao
                log.info("getExportExcelBuilder#listEngineerDetailByIdSet start [{}]", JSON.toJSONString(receiverIdList));
                ResponseDTO<List<ForeignEngineerDetailInfoDRO>> engineerListResp = engineerListRemoteService
                        .listEngineerDetailByIdSet(new HashSet<>(receiverIdList));
                log.info("getExportExcelBuilder#listEngineerDetailByIdSet end [{}]",JSON.toJSONString(engineerListResp));
                masterMap = Optional.ofNullable(engineerListResp.getData())
                        .filter(list -> list.size() > 0)
                        .map(list -> list.stream().collect(
                                Collectors.toMap(ForeignEngineerDetailInfoDRO::getEngineerId, ForeignEngineerDetailInfoDRO::getRealName, (k1, k2) -> k1)
                        ))
                        .orElseGet(Collections::emptyMap);
            }
            else {
                staffMap = Collections.emptyMap();
                masterMap = Collections.emptyMap();
            }

            // 查询厂商信息-录单员
            /*ResponseDTO<List<FactoryDRO>> factoryListResp = factoryListRemoteService.listByQuery(new FactoryQueryDIO());
            fcMap = Optional.ofNullable(factoryListResp.getData())
                    .filter(list -> list.size() > 0)
                    .map(list -> list.stream()
                            .collect(Collectors.toMap(FactoryDRO::getFactoryId, FactoryDRO::getCompanyName, (k1, k2) -> k1))
                    )
                    .orElseGet(Collections::emptyMap);*/
            fcMap = Collections.emptyMap();
        }

        // 业务线名称缓存
        HashMap<Integer, String> bizLineMap = Maps.newHashMap();

        sheet1.setCallback((fieldName, entity) -> {
            EsOrderWorkContact contact = entity.getContact();
            List<EsOrderWorkProduct> productList = entity.getProductList();
            EsOrderWorkFactory factory = entity.getFactoryOrder();
            List<EsOrderNonstandard> orderNonstandardList = Lists.newArrayList();
            if(CollectionUtil.isNotNullOrEmpty(entity.getOrderNonstandardList())){
                orderNonstandardList = entity.getOrderNonstandardList().stream().filter(e -> e.getType() == 1).collect(Collectors.toList());
            }
            switch (fieldName) {
                case "platCallback":
                    if (entity.getPlat() != null) {
                        return GlobalConsts.getPlatName(entity.getPlat());
                    }
                    break;
                case "platWorkCallback":
                    if (entity.getPlatWork() != null) {
                        return GlobalConsts.getPlatName(entity.getPlatWork());
                    }
                    break;
                case "cancelTimeCallback":
                    Date cancelTime = entity.getCancelTime();
                    if (Objects.nonNull(cancelTime)) {
                        return DateUtil.dateFormatToString(cancelTime, DateUtil.FORMAT_DEFAULT);
                    }
                    break;
                case "addressCallback":
                    if (contact != null) {
                        String street = contact.getStreet();
                        String address = contact.getAddress();
                        String addr = StringUtils.defaultString(street) + StringUtils.defaultString(address);
                        return showTel ? addr : StringUtil.hideTel(addr);
                    }
                    return null;
                case "userNameCallback":
                    if (contact != null && contact.getUserName() != null) {
                        return entity.getContact().getUserName();
                    }
                    return null;
                case "serviceProviderCallback":
                    return entity.getManageCompanyName();
                case "userPhoneNameCallback":
                    if (contact != null && contact.getPhone() != null) {
                        String[] phone = entity.getContact().getPhone();
                        String hideTel = MobileUtil.formatHideTel(phone[0]);
                        return showTel ? phone[0] : hideTel;
                    }
                    return null;
                case "genderCallback":
                    if (contact != null && contact.getGender() != null) {
                        String gender = GlobalDict.getGender(contact.getGender());
                        return gender;
                    }
                    return null;
                case "factoryCallback":
                    if (factory != null) {
                        return entity.getChannelName();
                    }
                    return null;
                case "factoryProductCallback":
                    if (factory != null) {
                        return factory.getProductName();
                    }
                    return null;
                case "bizTypeCallback":
                    return OrderConsts.getOrderBizType(entity.getBizType());
                case "bizLineCallback":
                    if (NumberUtil.isNotNullOrZero(entity.getBizLine())) {
                        // 业务线处理
                        String bizLineName = bizLineMap.get(entity.getBizLine());
                        if (Objects.nonNull(bizLineName)) {
                            return bizLineName;
                        }

                        ResponseDTO<Option<Integer>> nameVtRsp = productBusinessLineForeignListRemoteService.getOptionNameById(entity.getBizLine());
                        Option<Integer> vtDTO = nameVtRsp.getData();
                        if (Objects.nonNull(vtDTO)) {
                            bizLineMap.put(entity.getBizLine(), vtDTO.getLabel());
                            return vtDTO.getLabel();
                        }
                    }
                    return null;
                case "masterNameCallback":
                    String masterName = entity.getMasterName();
                    if (StringUtil.isNotBlank(masterName)) {
                        String hideTel = MobileUtil.formatHideTel(entity.getMasterPhone());
                        return masterName + ":" + (showTel ? entity.getMasterPhone() : hideTel);
                    }
                    break;
                case "slaveMasterNameCallback":
                    List<EsOrderWorkMaster> masterList = entity.getMasterList();
                    if (!org.springframework.util.CollectionUtils.isEmpty(masterList)) {
                        StringBuilder strb = new StringBuilder();
                        masterList.forEach(e -> {
                            if (Objects.equals(OrderConsts.ORDER_MASTER_TYPE_SLAVE, e.getMasterType())) {
                                String hideTel = MobileUtil.formatHideTel(e.getMasterPhone());
                                strb.append(StringUtils.defaultString(e.getMasterName()));
                                strb.append(":");
                                strb.append(showTel ? e.getMasterPhone() : hideTel);
                                strb.append(";");
                            }
                        });
                        return strb.toString();
                    }
                    break;
                case "reworkMasterNameCallback":
                    String reworkMasterName = entity.getReworkMasterName();
                    if (StringUtil.isNotBlank(reworkMasterName)) {
                        String hideTel = MobileUtil.formatHideTel(entity.getReworkMasterPhone());
                        return reworkMasterName + ":" + (showTel ? entity.getReworkMasterPhone() : hideTel);
                    }
                    break;
                case "masterSupervisorNameCallback":
                    String masterSupervisorName = entity.getMasterSupervisorName();
                    if (StringUtil.isNotBlank(masterSupervisorName)) {
                        String hideTel = MobileUtil.formatHideTel(entity.getMasterSupervisorPhone());
                        return masterSupervisorName + ":" + (showTel ? entity.getMasterSupervisorPhone() : hideTel);
                    }
                    break;
                case "showProductCallback":
                    if (!org.springframework.util.CollectionUtils.isEmpty(productList)) {
                        EsOrderWorkProduct esOrderWorkProduct = productList.get(0);
                        return esOrderWorkProduct.getShowProductName();
                    }
                    break;
                case "productCallback":
                    if (!org.springframework.util.CollectionUtils.isEmpty(productList)) {
                        EsOrderWorkProduct esOrderWorkProduct = productList.get(0);
                        return esOrderWorkProduct.getProductName();
                    }
                    break;
                case "standardPriceCallback":
                    Boolean isStandardPrice = entity.getIsStandardPrice();
                    String isStandardPriceStr;
                    if (isStandardPrice != null && isStandardPrice) {
                        isStandardPriceStr = "是";
                    } else {
                        isStandardPriceStr = "否";
                    }
                    return isStandardPriceStr;
                case "finalPriceRateCallback":
                    String finalPriceRateStr;
                    // 是标准收费单 并且符合一口价规则
                    isStandardPrice = entity.getIsStandardPrice();
                    if (isStandardPrice != null && isStandardPrice) {
                        boolean finalPrice = isFinalPrice(entity.getServiceItemList());
                        finalPriceRateStr = finalPrice ? "是" : "否";
                    } else {
                        finalPriceRateStr = "否";
                    }
                    return finalPriceRateStr;
                case "productUnitCallback":
                    if (!org.springframework.util.CollectionUtils.isEmpty(productList)) {
                        EsOrderWorkProduct esOrderWorkProduct = productList.get(0);
                        return esOrderWorkProduct.getProductUnit();
                    }
                    break;
                case "productBrandCallback":
                    if (!org.springframework.util.CollectionUtils.isEmpty(productList)) {
                        EsOrderWorkProduct esOrderWorkProduct = productList.get(0);
                        return esOrderWorkProduct.getBrandName();
                    }
                    break;
                case "productNumCallback":
                    if (!org.springframework.util.CollectionUtils.isEmpty(productList)) {
                        EsOrderWorkProduct esOrderWorkProduct = productList.get(0);
                        return esOrderWorkProduct.getNumber();
                    }
                    break;
                case "originalIdCallback":
                    return (entity.getOriginalId() != null && entity.getOriginalId() != 0) ? String.valueOf(entity.getOriginalId()) : "";
                case "originalAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getOriginalAmount());
                case "discountAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getDiscountAmount());
                case "totalAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getTotalAmount());
                case "channelPrepayAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getChannelPrepayAmount());
                case "depositAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getDepositAmount());
                case "masterAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getMasterAmount());
                case "refundAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getRefundAmount());
                case "channelAmountCallback":
                    return MoneyUtil.parseToYuanStr(entity.getChannelAmount());
                case "cancelContentCallback":
                    String failContent = entity.getFailContent();
                    String discardContent = entity.getDiscardContent();
                    return StringUtils.defaultString(failContent) + StringUtils.defaultString(discardContent);
                case "receiverNameCallBack":
                    Long receiverId = entity.getReceiverId();
                    Integer type = entity.getReceiverType();
                    Integer factoryId = -1;
                    if (entity.getFactoryOrder() != null) {
                        factoryId = entity.getFactoryOrder().getFactoryId();
                    }

                    if (!NumberUtil.isNullOrZero(receiverId)) {
                        if (receiverId == GlobalConsts.OPERATE_USER_TYPE_SYSTEM) {
                            return "系统";
                        } else if (String.valueOf(receiverId).length() > 10 && fcMap.containsKey(factoryId)) {
                            return fcMap.get(factoryId);
                        } else if (staffMap.containsKey(receiverId.intValue())) {
                            return staffMap.get(receiverId.intValue());
                        } else if (masterMap.containsKey(receiverId.intValue())) {
                            return masterMap.get(receiverId.intValue());
                        } else if (Objects.equals(GlobalConsts.OPERATE_USER_TYPE_USER, type)) {
                            return "用户";
                        } else {
                            return "系统";
                        }
                    } else {
                        return "其它";
                    }

                case "orderNonstandardTitleOneCallback":
                    if(CollectionUtil.isNotNullOrEmpty(orderNonstandardList)){
                        return orderNonstandardList.get(0).getTitle();
                    }
                    break;
                case "orderNonstandardContentOneCallback":
                    if(CollectionUtil.isNotNullOrEmpty(orderNonstandardList)){
                        return orderNonstandardList.get(0).getContent();
                    }
                    break;
                case "orderNonstandardTitleTwoCallback":
                    if (CollectionUtil.isNotNullOrEmpty(orderNonstandardList) && orderNonstandardList.size() > 1) {
                        return orderNonstandardList.get(1).getTitle();
                    }
                    break;
                case "orderNonstandardContentTwoCallback":
                    if (CollectionUtil.isNotNullOrEmpty(orderNonstandardList) && orderNonstandardList.size() > 1) {
                        return orderNonstandardList.get(1).getContent();
                    }
                    break;
                case "orderNonstandardTitleThreeCallback":
                    if (CollectionUtil.isNotNullOrEmpty(orderNonstandardList) && orderNonstandardList.size() > 2) {
                        return orderNonstandardList.get(2).getTitle();
                    }
                    break;
                case "orderNonstandardContentThreeCallback":
                    if (CollectionUtil.isNotNullOrEmpty(orderNonstandardList) && orderNonstandardList.size() > 2) {
                        return orderNonstandardList.get(2).getContent();
                    }
                    break;
                case "shopName":
                    Optional.ofNullable(entity.getChannelExtraData())
                            .map(extraData -> {
                                Matcher matcher = shopNamePattern.matcher(extraData);
                                return matcher.find() ? matcher.group(1) : null;
                            })
                            .orElse("");
                    break;
                default:
                    break;
            }
            return null;
        });
        sheet1.builderData();

        return excel;
    }

    /**
     * 查询订单数据
     * @param startDay
     * @param endDay
     * @return
     * @throws OmsBaseException
     */
    private List<EsOrderWork> listOrderWork(String startDay, String endDay) throws OmsBaseException {
        // 开始时间
        Date startDate = Optional.ofNullable(startDay)
                .map(val -> {
                    Date date = DateUtil.parse(val, "yyyy-MM-dd");
                    if (date == null) {
                        date = DateUtil.parse(val, "yyyyMMdd");
                    }
                    return date;
                })
                .orElseThrow(() -> new OmsBaseException("请提供正确的开始时间"));
        // 结束时间
        Date endDate = Optional.ofNullable(endDay)
                .map(val -> {
                    Date date = DateUtil.parse(val, "yyyy-MM-dd");
                    if (date == null) {
                        date = DateUtil.parse(val, "yyyyMMdd");
                    }
                    return date;
                })
                .orElseGet(() -> DateUtil.addMonth(startDate, 1));


        // 查询订单基本信息
        OrderWorkQuery query = new OrderWorkQuery();
        // 数据权限
        query.setPermit(GlobalConsts.YES);
        query.setPermitCompany(GlobalConsts.NO);
        query.setPermitService(GlobalConsts.NO);
        query.setPermitPlatformOrder(GlobalConsts.NO);
        query.setPermitPlatformServer(GlobalConsts.NO);
        query.setQueryWarning(GlobalConsts.YES);

        List<Integer> channelIds = new LinkedList<>();
        channelIds.add(DeshimanConsts.CHANNEL_ID);
        query.setChannelIdList(channelIds);

        String timeFmt = "yyyy-MM-dd 00:00:00";
        String receiveTime = DateUtil.toString(startDate, timeFmt) + "," + DateUtil.toString(endDate, timeFmt);
        query.setReceiveTime(receiveTime);
        query.setPageSize(5000);

        List<EsOrderWork> esOrderWorks = zsOrderWorkQueryBService.exportListOrderWorkByQuery(query);
        if (CollectionUtils.isEmpty(esOrderWorks)) {
            new OmsBaseException("没有订单数据");
        }
        if (esOrderWorks.size() >= 5000) {
            new OmsBaseException("数据太多，请适当缩小日期间隔！");
        }

        return esOrderWorks;
    }

    private final static List<String> matchingRule = Arrays.asList("特殊收费", "产品销售");

    /**
     * 判断是否是一口价
     *
     * @param serviceItemList
     * @return
     */
    private boolean isFinalPrice(List<EsOrderWorkServiceItem> serviceItemList) {
        boolean isFinalPrice = false;

        if (org.springframework.util.CollectionUtils.isEmpty(serviceItemList)) {
            return false;
        }

        for (EsOrderWorkServiceItem item : serviceItemList) {
            Integer price = item.getPrice();
            String serviceItemGroupName = item.getServiceItemGroupName();
            boolean b = !matchingRule.contains(serviceItemGroupName) || NumberUtil.isNullOrZero(price);
            if (b) {
                isFinalPrice = true;
                break;
            }
        }
        return isFinalPrice;
    }
}
